/****** Object:  Table [dbo].[CarModel]    Script Date: 12/08/2007 00:52:24 ******/
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CarModel]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[CarModel](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](50) COLLATE Arabic_CI_AS NOT NULL,
 CONSTRAINT [PK_CarModel] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
/****** Object:  Table [dbo].[WeatherStatus]    Script Date: 12/08/2007 00:52:25 ******/
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[WeatherStatus]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[WeatherStatus](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[Status] [nvarchar](50) COLLATE Arabic_CI_AS NOT NULL,
	[Description] [ntext] COLLATE Arabic_CI_AS NULL,
 CONSTRAINT [PK_WeatherStatus] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
/****** Object:  Table [dbo].[TimeOfDay]    Script Date: 12/08/2007 00:52:25 ******/
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TimeOfDay]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TimeOfDay](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](50) COLLATE Arabic_CI_AS NOT NULL,
	[Description] [ntext] COLLATE Arabic_CI_AS NULL,
 CONSTRAINT [PK_TimeOfDay] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
/****** Object:  Table [dbo].[Currency]    Script Date: 12/08/2007 00:52:25 ******/
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Currency]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Currency](
	[CurrencyCode] [char](3) COLLATE Arabic_CI_AS NOT NULL,
	[Name] [nvarchar](50) COLLATE Arabic_CI_AS NOT NULL,
	[Country_Id] [int] NULL,
 CONSTRAINT [PK_Currency] PRIMARY KEY CLUSTERED 
(
	[CurrencyCode] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
/****** Object:  Table [dbo].[StreetStatus]    Script Date: 12/08/2007 00:52:25 ******/
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[StreetStatus]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[StreetStatus](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](50) COLLATE Arabic_CI_AS NOT NULL,
	[Description] [ntext] COLLATE Arabic_CI_AS NULL,
 CONSTRAINT [PK_StreetStatus] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
/****** Object:  Table [dbo].[LocationType]    Script Date: 12/08/2007 00:52:25 ******/
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[LocationType]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[LocationType](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](50) COLLATE Arabic_CI_AS NOT NULL,
	[Description] [ntext] COLLATE Arabic_CI_AS NULL,
 CONSTRAINT [PK_LocationType] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
/****** Object:  Table [dbo].[Country]    Script Date: 12/08/2007 00:52:25 ******/
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Country]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Country](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[EnglishName] [varchar](50) COLLATE Arabic_CI_AS NOT NULL,
	[LocalName] [nvarchar](50) COLLATE Arabic_CI_AS NULL,
	[CountryCode] [char](3) COLLATE Arabic_CI_AS NOT NULL,
 CONSTRAINT [PK_Country] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY],
 CONSTRAINT [IX_Country] UNIQUE NONCLUSTERED 
(
	[CountryCode] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
/****** Object:  Table [dbo].[User]    Script Date: 12/08/2007 00:52:25 ******/
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[User]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[User](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](100) COLLATE Arabic_CI_AS NOT NULL,
	[Email] [nvarchar](100) COLLATE Arabic_CI_AS NOT NULL,
	[PasswordHash] [nvarchar](150) COLLATE Arabic_CI_AS NOT NULL,
	[Enabled] [bit] NOT NULL CONSTRAINT [DF_User_Status]  DEFAULT ((1)),
 CONSTRAINT [PK_User] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
/****** Object:  Table [dbo].[Journey]    Script Date: 12/08/2007 00:52:25 ******/
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Journey]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Journey](
	[Id] [int] NOT NULL,
	[Route_Id] [int] NOT NULL,
	[Fare] [decimal](18, 0) NOT NULL,
	[CurrencyCode] [char](3) COLLATE Arabic_CI_AS NOT NULL,
	[WeatherStatus_Id] [int] NULL,
	[StreetStatus_Id] [int] NULL,
	[JourneyDate] [smalldatetime] NOT NULL CONSTRAINT [DF_Journey_JourneyDate]  DEFAULT (getdate()),
	[TimeOfDay_Id] [int] NULL,
	[User_Id] [int] NULL,
	[CarModel_Id] [int] NULL,
	[Rate] [decimal](18, 0) NOT NULL CONSTRAINT [DF_Journey_Rate]  DEFAULT ((0)),
	[Story] [ntext] COLLATE Arabic_CI_AS NULL,
 CONSTRAINT [PK_Journey] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
/****** Object:  Table [dbo].[Location]    Script Date: 12/08/2007 00:52:25 ******/
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Location]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Location](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[LocationType_Id] [int] NOT NULL,
	[City_Id] [int] NOT NULL,
	[Region_Id] [int] NULL,
	[EnglishName] [varchar](50) COLLATE Arabic_CI_AS NOT NULL,
	[LocalName] [nvarchar](50) COLLATE Arabic_CI_AS NULL,
	[Longtitude] [decimal](18, 0) NULL,
	[Latitude] [decimal](18, 0) NULL,
 CONSTRAINT [PK_Location] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
/****** Object:  Table [dbo].[City]    Script Date: 12/08/2007 00:52:25 ******/
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[City]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[City](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[EnglishName] [varchar](100) COLLATE Arabic_CI_AS NOT NULL,
	[LocalName] [nvarchar](100) COLLATE Arabic_CI_AS NULL,
	[Country_Id] [int] NOT NULL,
 CONSTRAINT [PK_City] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
/****** Object:  Table [dbo].[Region]    Script Date: 12/08/2007 00:52:25 ******/
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Region]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Region](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[EnglishName] [varchar](50) COLLATE Arabic_CI_AS NOT NULL,
	[LocalName] [nvarchar](50) COLLATE Arabic_CI_AS NULL,
	[Country_Id] [int] NOT NULL,
 CONSTRAINT [PK_Region] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
/****** Object:  Table [dbo].[Route]    Script Date: 12/08/2007 00:52:25 ******/
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Route]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Route](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[FromLocation_Id] [int] NOT NULL,
	[ToLocation_Id] [int] NOT NULL,
 CONSTRAINT [PK_Route] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
/****** Object:  Table [dbo].[JourneyComment]    Script Date: 12/08/2007 00:52:25 ******/
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[JourneyComment]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[JourneyComment](
	[Journey_Id] [int] NOT NULL,
	[Comment_Id] [int] NOT NULL,
 CONSTRAINT [PK_JourneyComment] PRIMARY KEY CLUSTERED 
(
	[Journey_Id] ASC,
	[Comment_Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
/****** Object:  Table [dbo].[Comment]    Script Date: 12/08/2007 00:52:25 ******/
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Comment]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Comment](
	[Id] [int] NOT NULL,
	[Title] [nvarchar](50) COLLATE Arabic_CI_AS NULL,
	[CommentText] [ntext] COLLATE Arabic_CI_AS NOT NULL,
	[User_Id] [int] NOT NULL,
	[ReplyToComment_Id] [int] NULL,
	[CommentDate] [smalldatetime] NOT NULL CONSTRAINT [DF_Comment_CommentDate]  DEFAULT (getdate()),
	[Rate] [decimal](18, 0) NOT NULL CONSTRAINT [DF_Comment_Rate]  DEFAULT ((0)),
 CONSTRAINT [PK_Comment] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Journey_CarModel]') AND parent_object_id = OBJECT_ID(N'[dbo].[Journey]'))
ALTER TABLE [dbo].[Journey]  WITH CHECK ADD  CONSTRAINT [FK_Journey_CarModel] FOREIGN KEY([CarModel_Id])
REFERENCES [CarModel] ([Id])
ON UPDATE SET NULL
ON DELETE SET NULL
ALTER TABLE [dbo].[Journey] CHECK CONSTRAINT [FK_Journey_CarModel]
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Journey_Currency]') AND parent_object_id = OBJECT_ID(N'[dbo].[Journey]'))
ALTER TABLE [dbo].[Journey]  WITH CHECK ADD  CONSTRAINT [FK_Journey_Currency] FOREIGN KEY([CurrencyCode])
REFERENCES [Currency] ([CurrencyCode])
ON UPDATE CASCADE
ON DELETE CASCADE
ALTER TABLE [dbo].[Journey] CHECK CONSTRAINT [FK_Journey_Currency]
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Journey_Route]') AND parent_object_id = OBJECT_ID(N'[dbo].[Journey]'))
ALTER TABLE [dbo].[Journey]  WITH CHECK ADD  CONSTRAINT [FK_Journey_Route] FOREIGN KEY([Route_Id])
REFERENCES [Route] ([Id])
ON UPDATE CASCADE
ON DELETE CASCADE
ALTER TABLE [dbo].[Journey] CHECK CONSTRAINT [FK_Journey_Route]
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Journey_StreetStatus]') AND parent_object_id = OBJECT_ID(N'[dbo].[Journey]'))
ALTER TABLE [dbo].[Journey]  WITH CHECK ADD  CONSTRAINT [FK_Journey_StreetStatus] FOREIGN KEY([StreetStatus_Id])
REFERENCES [StreetStatus] ([Id])
ON UPDATE SET NULL
ON DELETE SET NULL
ALTER TABLE [dbo].[Journey] CHECK CONSTRAINT [FK_Journey_StreetStatus]
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Journey_TimeOfDay]') AND parent_object_id = OBJECT_ID(N'[dbo].[Journey]'))
ALTER TABLE [dbo].[Journey]  WITH CHECK ADD  CONSTRAINT [FK_Journey_TimeOfDay] FOREIGN KEY([TimeOfDay_Id])
REFERENCES [TimeOfDay] ([Id])
ON UPDATE SET NULL
ON DELETE SET NULL
ALTER TABLE [dbo].[Journey] CHECK CONSTRAINT [FK_Journey_TimeOfDay]
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Journey_User]') AND parent_object_id = OBJECT_ID(N'[dbo].[Journey]'))
ALTER TABLE [dbo].[Journey]  WITH CHECK ADD  CONSTRAINT [FK_Journey_User] FOREIGN KEY([User_Id])
REFERENCES [User] ([Id])
ON UPDATE SET NULL
ON DELETE SET NULL
ALTER TABLE [dbo].[Journey] CHECK CONSTRAINT [FK_Journey_User]
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Journey_WeatherStatus]') AND parent_object_id = OBJECT_ID(N'[dbo].[Journey]'))
ALTER TABLE [dbo].[Journey]  WITH CHECK ADD  CONSTRAINT [FK_Journey_WeatherStatus] FOREIGN KEY([WeatherStatus_Id])
REFERENCES [WeatherStatus] ([Id])
ON UPDATE SET NULL
ON DELETE SET NULL
ALTER TABLE [dbo].[Journey] CHECK CONSTRAINT [FK_Journey_WeatherStatus]
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Location_City]') AND parent_object_id = OBJECT_ID(N'[dbo].[Location]'))
ALTER TABLE [dbo].[Location]  WITH CHECK ADD  CONSTRAINT [FK_Location_City] FOREIGN KEY([City_Id])
REFERENCES [City] ([Id])
ON UPDATE CASCADE
ON DELETE CASCADE
ALTER TABLE [dbo].[Location] CHECK CONSTRAINT [FK_Location_City]
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Location_LocationType]') AND parent_object_id = OBJECT_ID(N'[dbo].[Location]'))
ALTER TABLE [dbo].[Location]  WITH CHECK ADD  CONSTRAINT [FK_Location_LocationType] FOREIGN KEY([LocationType_Id])
REFERENCES [LocationType] ([Id])
ON UPDATE CASCADE
ON DELETE CASCADE
ALTER TABLE [dbo].[Location] CHECK CONSTRAINT [FK_Location_LocationType]
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Location_Region]') AND parent_object_id = OBJECT_ID(N'[dbo].[Location]'))
ALTER TABLE [dbo].[Location]  WITH CHECK ADD  CONSTRAINT [FK_Location_Region] FOREIGN KEY([Region_Id])
REFERENCES [Region] ([Id])
ON DELETE SET NULL
ALTER TABLE [dbo].[Location] CHECK CONSTRAINT [FK_Location_Region]
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_City_Country]') AND parent_object_id = OBJECT_ID(N'[dbo].[City]'))
ALTER TABLE [dbo].[City]  WITH CHECK ADD  CONSTRAINT [FK_City_Country] FOREIGN KEY([Country_Id])
REFERENCES [Country] ([Id])
ALTER TABLE [dbo].[City] CHECK CONSTRAINT [FK_City_Country]
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Region_Country]') AND parent_object_id = OBJECT_ID(N'[dbo].[Region]'))
ALTER TABLE [dbo].[Region]  WITH CHECK ADD  CONSTRAINT [FK_Region_Country] FOREIGN KEY([Country_Id])
REFERENCES [Country] ([Id])
ALTER TABLE [dbo].[Region] CHECK CONSTRAINT [FK_Region_Country]
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Route_Location]') AND parent_object_id = OBJECT_ID(N'[dbo].[Route]'))
ALTER TABLE [dbo].[Route]  WITH CHECK ADD  CONSTRAINT [FK_Route_Location] FOREIGN KEY([FromLocation_Id])
REFERENCES [Location] ([Id])
ALTER TABLE [dbo].[Route] CHECK CONSTRAINT [FK_Route_Location]
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Route_Location1]') AND parent_object_id = OBJECT_ID(N'[dbo].[Route]'))
ALTER TABLE [dbo].[Route]  WITH CHECK ADD  CONSTRAINT [FK_Route_Location1] FOREIGN KEY([ToLocation_Id])
REFERENCES [Location] ([Id])
ALTER TABLE [dbo].[Route] CHECK CONSTRAINT [FK_Route_Location1]
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_JourneyComment_Comment]') AND parent_object_id = OBJECT_ID(N'[dbo].[JourneyComment]'))
ALTER TABLE [dbo].[JourneyComment]  WITH CHECK ADD  CONSTRAINT [FK_JourneyComment_Comment] FOREIGN KEY([Comment_Id])
REFERENCES [Comment] ([Id])
ON UPDATE CASCADE
ON DELETE CASCADE
ALTER TABLE [dbo].[JourneyComment] CHECK CONSTRAINT [FK_JourneyComment_Comment]
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_JourneyComment_Journey]') AND parent_object_id = OBJECT_ID(N'[dbo].[JourneyComment]'))
ALTER TABLE [dbo].[JourneyComment]  WITH CHECK ADD  CONSTRAINT [FK_JourneyComment_Journey] FOREIGN KEY([Journey_Id])
REFERENCES [Journey] ([Id])
ON UPDATE CASCADE
ON DELETE CASCADE
ALTER TABLE [dbo].[JourneyComment] CHECK CONSTRAINT [FK_JourneyComment_Journey]
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Comment_Comment]') AND parent_object_id = OBJECT_ID(N'[dbo].[Comment]'))
ALTER TABLE [dbo].[Comment]  WITH CHECK ADD  CONSTRAINT [FK_Comment_Comment] FOREIGN KEY([ReplyToComment_Id])
REFERENCES [Comment] ([Id])
ALTER TABLE [dbo].[Comment] CHECK CONSTRAINT [FK_Comment_Comment]
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Comment_User]') AND parent_object_id = OBJECT_ID(N'[dbo].[Comment]'))
ALTER TABLE [dbo].[Comment]  WITH CHECK ADD  CONSTRAINT [FK_Comment_User] FOREIGN KEY([User_Id])
REFERENCES [User] ([Id])
ALTER TABLE [dbo].[Comment] CHECK CONSTRAINT [FK_Comment_User]


